package com.ruoyi.ucar.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruoyi.ucar.domain.TContractTool;
import com.ruoyi.ucar.domain.po.ContractToolDetailQueryPo;
import com.ruoyi.ucar.domain.po.ContractToolListQueryPo;
import com.ruoyi.ucar.moreq.ContractToolDetailQueryMoReq;
import com.ruoyi.ucar.moreq.ContractToolListQueryMoReq;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 合同工具Mapper接口
 * 
 * @author sungangbin
 * @date 2025-05-13
 */
@Mapper
public interface TContractToolMapper extends BaseMapper<TContractTool>
{
    /**
     * 查询合同工具
     * 
     * @param id 合同工具主键
     * @return 合同工具
     */
    public TContractTool selectTContractToolById(Long id);

    /**
     * 查询合同工具列表
     * 
     * @param tContractTool 合同工具
     * @return 合同工具集合
     */
    public List<TContractTool> selectTContractToolList(TContractTool tContractTool);

    /**
     * 新增合同工具
     * 
     * @param tContractTool 合同工具
     * @return 结果
     */
    public int insertTContractTool(TContractTool tContractTool);

    /**
     * 修改合同工具
     * 
     * @param tContractTool 合同工具
     * @return 结果
     */
    public int updateTContractTool(TContractTool tContractTool);

    /**
     * 删除合同工具
     * 
     * @param id 合同工具主键
     * @return 结果
     */
    public int deleteTContractToolById(Long id);

    /**
     * 批量删除合同工具
     * 
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteTContractToolByIds(Long[] ids);

    @Select("<script>" +
            "SELECT " +
            "  tt.id as id, " +
            "  tt.tool_name as toolName, " +
            "  tt.contract_tool_uuid as contractToolUuid, " +
            "  tt.status as  status, " +
            "  tt.remark as remark, " +
            "  tt.upload_datetime as uploadDatetime, " +
            "  tt.file_main_uuid as fileMainUuid, " +
            "  fd.file_url as fileUrl " +
            "FROM " +
            "  t_contract_tool tt " +
            "  LEFT JOIN sys_file_main fm on tt.file_main_uuid=fm.file_main_uuid " +
            "  LEFT JOIN sys_file_data fd ON fm.file_main_uuid = fd.file_main_uuid " +
            "<where>" +
            "   <if test='queryParams.deleteFlag != null'>" +
            "       AND (tt.delete_flag = #{queryParams.deleteFlag} " +
            "       AND fm.delete_flag = #{queryParams.deleteFlag} " +
            "       AND fd.delete_flag = #{queryParams.deleteFlag}) " +
            "   </if>" +
            "   <if test='queryParams.id != null'> AND tt.id = #{queryParams.id} </if>" +
            "   <if test='queryParams.contractToolUuid != null'> AND tt.contract_tool_uuid = #{queryParams.contractToolUuid} </if>" +
            "</where>" +
            "</script>")
    public List<ContractToolDetailQueryPo> contractToolDetailQuery(@Param("queryParams") ContractToolDetailQueryMoReq contractToolDetailQueryMoReq);


    @Select("<script>" +
            "SELECT " +
            "  tt.id as id, " +
            "  tt.tool_name as toolName, " +
            "  tt.contract_tool_uuid as contractToolUuid, " +
            "  tt.status as  status, " +
            "  tt.remark as remark, " +
            "  tt.upload_datetime as uploadDatetime, " +
            "  tt.file_main_uuid as fileMainUuid, " +
            "  fd.file_url as fileUrl " +
            "FROM " +
            "  t_contract_tool tt " +
            "  LEFT JOIN sys_file_main fm on tt.file_main_uuid=fm.file_main_uuid " +
            "  LEFT JOIN sys_file_data fd ON fm.file_main_uuid = fd.file_main_uuid " +
            "<where>" +
            "   <if test='queryParams.deleteFlag != null'>" +
            "       AND (tt.delete_flag = #{queryParams.deleteFlag} " +
            "       AND fm.delete_flag = #{queryParams.deleteFlag} " +
            "       AND fd.delete_flag = #{queryParams.deleteFlag}) " +
            "   </if>" +
            "</where>" +
            "</script>")
    public IPage<ContractToolListQueryPo> contractToolListQueryPage(IPage<ContractToolListQueryPo> page, @Param("queryParams") ContractToolListQueryMoReq contractToolListQueryMoReq);

    @Select("<script>" +
            "SELECT " +
            "  tt.id as id, " +
            "  tt.tool_name as toolName, " +
            "  tt.contract_tool_uuid as contractToolUuid, " +
            "  tt.status as  status, " +
            "  tt.remark as remark, " +
            "  tt.upload_datetime as uploadDatetime, " +
            "  tt.file_main_uuid as fileMainUuid, " +
            "  fd.file_url as fileUrl " +
            "FROM " +
            "  t_contract_tool tt " +
            "  LEFT JOIN sys_file_main fm on tt.file_main_uuid=fm.file_main_uuid " +
            "  LEFT JOIN sys_file_data fd ON fm.file_main_uuid = fd.file_main_uuid " +
            "<where>" +
            "   <if test='queryParams.deleteFlag != null'>" +
            "       AND (tt.delete_flag = #{queryParams.deleteFlag} " +
            "       AND fm.delete_flag = #{queryParams.deleteFlag} " +
            "       AND fd.delete_flag = #{queryParams.deleteFlag}) " +
            "   </if>" +
            "</where>" +
            "</script>")
    public List<ContractToolListQueryPo> contractToolListMobileQuery(  @Param("queryParams") ContractToolListQueryMoReq contractToolListQueryMoReq);

}
